package com.group.mall.service.Impl;

import com.group.mall.domain.DTO.UserDTO;
import com.group.mall.domain.POJO.User;
import com.group.mall.mapper.UserMapper;
import com.group.mall.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //添加用户
    @Override
    public Boolean addUser(UserDTO userDTO) {
        User user = new User();
        BeanUtils.copyProperties(userDTO, user);

        user.setStatus(1);
        user.setBalance(0);
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());

        log.info("新增用户：{}", user);
        return userMapper.addUser(user);
    }

    @Override
    public List<User> getUser(Long id) {
        return userMapper.getUser(id);
    }

    @Override
    public List<User> getUsername(String username) {
        return userMapper.getUsername(username);
    }

    @Override
    public void updateUser(UserDTO userDTO) {
       userMapper.updateUser(userDTO);
    }

    @Override
    public List<User> getBalance(Long id) {
        return userMapper.getBalance(id);
    }

    @Override
    public void updateRecharge(User user) {
        userMapper.updateRecharge(user);
    }


    @Override
    public User getUserList(Integer userId) {
        return userMapper.getUserList(userId);
    }
}
